package main

import (
	"context"
	"go_final/demos/proto_vs_json/proto"
	"net"

	"google.golang.org/grpc"
)

type Server struct {
	proto.UnimplementedHelloServer
}

func (s *Server) Hello(ctx context.Context, in *proto.HelloRequest) (*proto.HelloResponse,
	error) {
	return &proto.HelloResponse{
		Reply: in.Name + " I'm fine!",
	}, nil
}

func main() {
	// 1.新建一个serve
	s := grpc.NewServer()

	// 2.注册服务
	proto.RegisterHelloServer(s, &Server{})

	// 3. 监听端口
	listener, err := net.Listen("tcp", ":8081")
	if err != nil {
		panic("failed to listen: " + err.Error())
	}
	_ = s.Serve(listener)
}
